package com.company.project.demo.common.enums;


import com.base.common.model.dto.EnumDto;

import java.util.LinkedList;
import java.util.List;

/**
 * @Description 性别
 * @Author zhongbo.yu
 * @Date 2021/12/28
 */
public enum SexEnum {
    /**
     * 性别：0未知 1男 2女
     */
    WZ("0", "未知"),
    M("1", "男"),
    F("2", "女");

    private final String code;
    private final String value;

    private SexEnum(final String code, final String value) {
        this.code = code;
        this.value = value;
    }

    public static String getValue(String code) {
        SexEnum[] goodsEnum = values();
        for (SexEnum goodsModeEnum : goodsEnum) {
            if (goodsModeEnum.code().equals(code)) {
                return goodsModeEnum.value();
            }
        }
        return null;
    }

    public static SexEnum getEnum(String code) {
        SexEnum[] goodsEnum = values();
        for (SexEnum goodsModeEnum : goodsEnum) {
            if (goodsModeEnum.code().equals(code)) {
                return goodsModeEnum;
            }
        }
        return null;
    }

    public static List<EnumDto> getList() {
        List<EnumDto> list = new LinkedList<>();
        for (SexEnum em : values()) {
            list.add(EnumDto.builder().code(em.code).value(em.value).build());
        }
        return list;
    }

    public String code() {
        return this.code;
    }

    public String value() {
        return this.value;
    }
}
